package com.ruoyi.framework.config;

import com.ruoyi.common.config.Global;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 配置 Thymeleaf 全局常量
 * @author: wenchao
 * @date: 2019-11-17
 */
@Configuration
public class ThymeleafConfig {

    @Resource
    public void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
        if (viewResolver != null) {
            Map<String, Object> vars = new HashMap<>(16);
            vars.put("ctx", Global.getAdminPath());
            vars.put("sys-name", Global.getName());
            vars.put("sys-code", Global.getCode());
            vars.put("sys-version", Global.getVersion());
            vars.put("sys-copyrightYear", Global.getCopyrightYear());
            vars.put("sys-author", Global.getAuthor());
            vars.put("sys-email", Global.getEmail());
            vars.put("fctx", Global.getFrontPath());
            vars.put("captchaType", Global.getConfig("shiro.user.captchaType"));
            vars.put("captchaEnabled", Global.getConfig("shiro.user.captchaEnabled"));
            viewResolver.setStaticVariables(vars);
        }
    }
}
